from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from flask_script import Shell, Manager

app = Flask(__name__)
manager = Manager(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://pi:wangaicc@192.168.100.3:5432/test'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)


class Kuaidi(db.Model):
    __tablename__ = 'kuaidi'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, info='编码')
    name = db.Column(db.String, info='收件人名')
    phone = db.Column(db.String, info='收件人手机号码', index=True)
    kuaidi_no = db.Column(db.String, info='快递单号', index=True, unique=True)
    kuaidi_ty = db.Column(db.String, info='快递公司', default="ems")
    kdstatus = db.Column(db.String, info='快递目前状态', nullable=True)
    kdcxshisj = db.Column(db.String, info="快递查询时间", nullable=True)

    def __init__(self, name, phone, kuaidi_no, kuaidi_ty):
        self.name = name
        self.phone = phone
        self.kuaidi_no = kuaidi_no
        self.ctikuaidi_tyme = kuaidi_ty

    def __repr__(self):
        return "<User {} NO. {}>" .format(self.name, self.kuaidi_no)


if __name__ == "__main__":
    manager.run()
